package com.ktwlrj.securitycenter.controller;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ktwlrj.core.base.ActionResult;
import com.ktwlrj.core.base.SuperController;
import com.ktwlrj.core.exception.ActionException;
import com.ktwlrj.core.validation.group.Insert;
import com.ktwlrj.core.validation.group.Update;
import com.ktwlrj.securitycenter.controller.args.SafeApproveArgs;
import com.ktwlrj.securitycenter.controller.args.SafeSpecialApplyArgs;
import com.ktwlrj.securitycenter.controller.args.SafeSpecialApprovePageArgs;
import com.ktwlrj.securitycenter.controller.args.SafeSpecialFormArgs;
import com.ktwlrj.securitycenter.controller.args.SafeSpecialPageArgs;
import com.ktwlrj.securitycenter.dto.SafeSpecialApprovePageDto;
import com.ktwlrj.securitycenter.dto.SafeSpecialFormDto;
import com.ktwlrj.securitycenter.dto.SafeSpecialPageDto;
import com.ktwlrj.securitycenter.service.SafeSpecialService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 特殊房屋交易
 *
 * @author lisc
 * @date 2020-02-24 18:08:13
 * @since JDK1.8
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@Api(tags = "SafeSpecial", value = "SafeSpecialApi", description = "SafeSpecialApi接口相关", hidden = true)
@RequestMapping(value = "safeSpecial", produces = MediaType.APPLICATION_JSON_VALUE)
public class SafeSpecialController extends SuperController {
	private final SafeSpecialService service;

	/**
	 * 特殊房屋交易添加
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "添加(v1.0.0)", notes = "添加")
	@PostMapping(value = "/insert")
	public ActionResult<String> insert(@RequestBody @Validated(Insert.class) SafeSpecialFormArgs args)
			throws ActionException {
		args.getSafeSpecial().setSpecialType(1);
		service.save(args);
		return success("添加成功");
	}

	/**
	 * 特殊房屋交易修改
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "通过主键id修改(v1.0.0)", notes = "修改")
	@PostMapping(value = "/update")
	public ActionResult<Object> update(@RequestBody @Validated(Update.class) SafeSpecialFormArgs args)
			throws ActionException {
		service.updateById(args);
		return success("修改成功");
	}

	/**
	 * 特殊房屋交易逻辑删除
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "逻辑删除(v1.0.0)", notes = "删除")
	@ApiImplicitParam(paramType = "query", value = "主键id", name = "specialId", required = true)
	@GetMapping(value = "/delete")
	public ActionResult<String> delete(@NotBlank(message = "主键id不能为空") String specialId) throws ActionException {
		service.deleteById(specialId);
		return success("删除成功");
	}

	/**
	 * 特殊房屋交易删除申请提交
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "删除申请提交(v1.0.0)", notes = "删除申请提交")
	@PostMapping(value = "/deleteApply")
	public ActionResult<String> deleteApply(@RequestBody SafeSpecialApplyArgs args) throws ActionException {
		service.deleteApply(args);
		return success("删除申请提交成功");
	}

	/**
	 * 通过id查询特殊房屋交易
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "通过主键id查询详情(v1.0.0)", notes = "查询详情")
	@ApiImplicitParam(paramType = "query", value = "主键id", name = "specialId", required = true)
	@GetMapping(value = "/select/by-id")
	public ActionResult<SafeSpecialFormDto> getById(@NotBlank(message = "主键id不能为空") String specialId)
			throws ActionException {
		return success(service.getById(specialId));
	}

	/**
	 * 提交特殊房屋交易
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "提交特殊房屋交易(v1.0.0)", notes = "提交特殊房屋交易")
	@PostMapping(value = "/submit")
	public ActionResult<String> submit(@RequestBody SafeSpecialApplyArgs args) throws ActionException {
		service.submit(args);
		return success("提交成功");
	}

	/**
	 * 变更并新增
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "变更并新增(v1.0.0)", notes = "变更并新增")
	@PostMapping(value = "/changeInsert")
	public ActionResult<String> changeInsert(@RequestBody SafeSpecialFormArgs args) throws ActionException {
		args.getSafeSpecial().setSpecialType(2);
		service.changeInsert(args);
		return success("提交成功");
	}

	/**
	 * 分页查询特殊房屋交易
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "分页查询(v1.0.0)", notes = "分页查询")
	@PostMapping(value = "/select/page")
	public ActionResult<IPage<SafeSpecialPageDto>> selectPage(@RequestBody @Valid SafeSpecialPageArgs args)
			throws ActionException {
		return success(service.page(args));
	}

	/**
	 * 历史分页查询特殊房屋交易
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "历史分页查询特殊房屋交易(v1.0.0)", notes = "历史分页查询特殊房屋交易")
	@PostMapping(value = "/historyPage")
	public ActionResult<IPage<SafeSpecialPageDto>> historyPage(@RequestBody @Valid SafeSpecialPageArgs args)
			throws ActionException {
		return success(service.historyPage(args));
	}

	/**
	 * 审批分页查询特殊房屋交易
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "审批分页查询特殊房屋交易(v1.0.0)", notes = "审批分页查询特殊房屋交易")
	@PostMapping(value = "/approvePage")
	public ActionResult<IPage<SafeSpecialApprovePageDto>> approvePage(
			@RequestBody @Valid SafeSpecialApprovePageArgs args) throws ActionException {
		return success(service.approvePage(args));
	}

	/**
	 * 业务放行审批处理
	 * 
	 * @param args
	 * @return
	 * @throws ActionException
	 */
	@ApiOperation(value = "业务放行审批处理(v1.0.0)", notes = "业务放行审批处理")
	@PostMapping(value = "/approveHandle")
	public ActionResult<String> approveHandle(@RequestBody @Valid SafeApproveArgs args) throws ActionException {
		service.approveHandle(args);
		return success("审批处理成功");
	}
}